<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - opt_qp_solver.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2010  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>optimization.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>sstream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cstdlib<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>ctime<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>rand.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>string.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>statistics.h<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='tester.h.html'>tester.h</a>"


<font color='#0000FF'>namespace</font>  
<b>{</b>

    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> test;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;

    logger <b><a name='dlog'></a>dlog</b><font face='Lucida Console'>(</font>"<font color='#CC0000'>test.opt_qp_solver</font>"<font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='test_smo'></a>test_smo</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <font color='#0000FF'><u>double</u></font> penalty;
        <font color='#0000FF'><u>double</u></font> C;

        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> alpha
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>

            <font color='#0000FF'><u>double</u></font> obj <font color='#5555FF'>=</font>  <font color='#979000'>0.5</font><font color='#5555FF'>*</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>Q<font color='#5555FF'>*</font>alpha <font color='#5555FF'>-</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>b;
            <font color='#0000FF'><u>double</u></font> c1 <font color='#5555FF'>=</font> <font color='#BB00BB'>pow</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>-</font>C,<font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>double</u></font> c2 <font color='#5555FF'>=</font> <font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font><font color='#BB00BB'>pow</font><font face='Lucida Console'>(</font><font color='#BB00BB'>pointwise_multiply</font><font face='Lucida Console'>(</font>alpha, alpha<font color='#5555FF'>&lt;</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            obj <font color='#5555FF'>+</font><font color='#5555FF'>=</font> penalty<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>c1 <font color='#5555FF'>+</font> c2<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>return</font> obj;
        <b>}</b>

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> Q, b;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='test_smo_derivative'></a>test_smo_derivative</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <font color='#0000FF'><u>double</u></font> penalty;
        <font color='#0000FF'><u>double</u></font> C;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> alpha
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>

            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> obj <font color='#5555FF'>=</font>  Q<font color='#5555FF'>*</font>alpha <font color='#5555FF'>-</font> b;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> c1 <font color='#5555FF'>=</font> uniform_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>alpha.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font>, <font color='#979000'>2</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>-</font>C<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> c2 <font color='#5555FF'>=</font> <font color='#979000'>2</font><font color='#5555FF'>*</font><font color='#BB00BB'>pointwise_multiply</font><font face='Lucida Console'>(</font>alpha, alpha<font color='#5555FF'>&lt;</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            
            <font color='#0000FF'>return</font> obj <font color='#5555FF'>+</font> penalty<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>c1 <font color='#5555FF'>+</font> c2<font face='Lucida Console'>)</font>;
        <b>}</b>

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> Q, b;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> <b><a name='compute_objective_value'></a>compute_objective_value</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> w,
        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> A,
        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> b,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>dot</font><font face='Lucida Console'>(</font>w,w<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> C<font color='#5555FF'>*</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>w <font color='#5555FF'>+</font> b<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test1'></a>test_qp4_test1</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,
        <font color='#5555FF'>-</font><font color='#979000'>3</font>,<font color='#979000'>1</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#979000'>2</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>true_alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha:      </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        true_alpha <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>2</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>true alpha: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>true_alpha<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha error: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test2'></a>test_qp4_test2</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,
        <font color='#979000'>3</font>,<font color='#5555FF'>-</font><font color='#979000'>1</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#979000'>2</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>true_alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>0.25</font>, <font color='#979000'>0</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha:      </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        true_alpha <font color='#5555FF'>=</font> <font color='#979000'>0.43750</font>, <font color='#979000'>1.56250</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>true alpha: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>true_alpha<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha error: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test3'></a>test_qp4_test3</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,
        <font color='#5555FF'>-</font><font color='#979000'>3</font>,<font color='#5555FF'>-</font><font color='#979000'>1</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#979000'>2</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>true_alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>2</font>, <font color='#979000'>0</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha:      </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        true_alpha <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>2</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>true alpha: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>true_alpha<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha error: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test5'></a>test_qp4_test5</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,<font color='#979000'>4</font>,
        <font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>6</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>,<font color='#5555FF'>-</font><font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#979000'>2</font>,
        <font color='#979000'>3</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>true_alpha</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>, <font color='#979000'>0</font>;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;


        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>0</font>, <font color='#979000'>0.11111111111111111111</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha:      </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        true_alpha <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>0.432098765432099</font>, <font color='#979000'>1.567901234567901</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>true alpha: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>true_alpha<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha error: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test4'></a>test_qp4_test4</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,
        <font color='#979000'>3</font>,<font color='#979000'>1</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#979000'>2</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> computed_obj <font color='#5555FF'>=</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>0</font>, <font color='#979000'>0</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> true_obj <font color='#5555FF'>=</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> computed_obj;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> true_obj;

        <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>computed_obj <font color='#5555FF'>-</font> true_obj<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>8</font>, <font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>computed_obj <font color='#5555FF'>-</font> true_obj<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test6'></a>test_qp4_test6</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#979000'>1</font>,<font color='#979000'>2</font>,<font color='#979000'>4</font>,
        <font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>6</font>,
        <font color='#979000'>6</font>,<font color='#979000'>7</font>,<font color='#5555FF'>-</font><font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>,
        <font color='#5555FF'>-</font><font color='#979000'>2</font>,
        <font color='#5555FF'>-</font><font color='#979000'>3</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>, <font color='#979000'>0</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> iters <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, <font color='#BB00BB'>tmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>A<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>A<font face='Lucida Console'>)</font>, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>3000</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w <font color='#5555FF'>=</font> <font color='#BB00BB'>lowerbound</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>A<font color='#5555FF'>*</font>alpha, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>lambda: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>lambda<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>w:     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;


        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> computed_obj <font color='#5555FF'>=</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        w <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>0</font>, <font color='#979000'>0</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> true_obj <font color='#5555FF'>=</font> <font color='#BB00BB'>compute_objective_value</font><font face='Lucida Console'>(</font>w,A,b,C<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>computed obj:      </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> computed_obj;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>with true w obj:   </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> true_obj;

        <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>computed_obj <font color='#5555FF'>-</font> true_obj<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>8</font>, 
            "<font color='#CC0000'>computed_obj: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> computed_obj <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>  true_obj: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> true_obj <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>  delta: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>  <font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>computed_obj <font color='#5555FF'>-</font> true_obj<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>  iters: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n  alpha: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>   lambda: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>lambda<font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> <b><a name='test_qp4_test7'></a>test_qp4_test7</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>A</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        A <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>,<font color='#979000'>2</font>,<font color='#979000'>4</font>,
        <font color='#5555FF'>-</font><font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>6</font>,
        <font color='#5555FF'>-</font><font color='#979000'>6</font>,<font color='#979000'>7</font>,<font color='#5555FF'>-</font><font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        b <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>,
        <font color='#5555FF'>-</font><font color='#979000'>2</font>,
        <font color='#979000'>3</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>Q</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>,<font color='#979000'>3</font><font face='Lucida Console'>)</font>;
        Q <font color='#5555FF'>=</font> <font color='#979000'>4</font>,<font color='#5555FF'>-</font><font color='#979000'>5</font>,<font color='#979000'>6</font>,
        <font color='#979000'>1</font>,<font color='#5555FF'>-</font><font color='#979000'>4</font>,<font color='#979000'>2</font>,
        <font color='#5555FF'>-</font><font color='#979000'>9</font>,<font color='#5555FF'>-</font><font color='#979000'>4</font>,<font color='#979000'>5</font>;
        Q <font color='#5555FF'>=</font> Q<font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>Q<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> C <font color='#5555FF'>=</font> <font color='#979000'>2</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>true_alpha</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>d</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, lambda;
        alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font><font color='#979000'>2</font>, C<font color='#5555FF'>/</font><font color='#979000'>2</font>, <font color='#979000'>0</font>;
        d <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#BB00BB'>solve_qp4_using_smo</font><font face='Lucida Console'>(</font>A, Q, b, d, alpha, lambda, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>800</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>*******************************************************</font>";

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha:      </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
        true_alpha <font color='#5555FF'>=</font> <font color='#979000'>0</font>, <font color='#979000'>2</font>, <font color='#979000'>0</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>true alpha: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>true_alpha<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha error: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>-</font>true_alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_solve_qp4_using_smo'></a>test_solve_qp4_using_smo</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>test_qp4_test1</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test2</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test3</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test4</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test5</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test6</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>test_qp4_test7</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> <b><a name='max_distance_to'></a>max_distance_to</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> aa : a<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> bb : b<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>aa<font color='#5555FF'>-</font>bb<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&gt;</font> best_dist<font face='Lucida Console'>)</font>
                    best_dist <font color='#5555FF'>=</font> dist;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> best_dist;
    <b>}</b>

    <font color='#0000FF'><u>double</u></font> <b><a name='min_distance_to'></a>min_distance_to</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> aa : a<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> bb : b<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>aa<font color='#5555FF'>-</font>bb<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
                    best_dist <font color='#5555FF'>=</font> dist;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> best_dist;
    <b>}</b>

    <font color='#0000FF'><u>double</u></font> <b><a name='min_distance_to'></a>min_distance_to</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> s,
        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> v
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> x : s<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>v<font color='#5555FF'>-</font>x<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&lt;</font> best_dist<font face='Lucida Console'>)</font>
            <b>{</b>
                best_dist <font color='#5555FF'>=</font> dist;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> best_dist;
    <b>}</b>

    <font color='#0000FF'><u>double</u></font> <b><a name='max_distance_to'></a>max_distance_to</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> s,
        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> v
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> x : s<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>v<font color='#5555FF'>-</font>x<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'>&gt;</font> best_dist<font face='Lucida Console'>)</font>
            <b>{</b>
                best_dist <font color='#5555FF'>=</font> dist;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> best_dist;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> <b><a name='test_find_gap_between_convex_hulls'></a>test_find_gap_between_convex_hulls</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> set1, set2;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> dist_thresh <font color='#5555FF'>=</font> <font color='#979000'>5.47723</font>; 

        <font color='#009900'>// generate two groups of points that are pairwise close within each set and
</font>        <font color='#009900'>// pairwise far apart between each set, according to dist_thresh distance threshold.  
</font>        <font color='#0000FF'><u>bool</u></font> which <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font color='#979000'>10000</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> v <font color='#5555FF'>=</font> <font color='#BB00BB'>gaussian_randm</font><font face='Lucida Console'>(</font><font color='#979000'>15</font>,<font color='#979000'>1</font>,i<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> min_dist1 <font color='#5555FF'>=</font> <font color='#BB00BB'>min_distance_to</font><font face='Lucida Console'>(</font>set1,v<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> min_dist2 <font color='#5555FF'>=</font> <font color='#BB00BB'>min_distance_to</font><font face='Lucida Console'>(</font>set2,v<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> max_dist1 <font color='#5555FF'>=</font> <font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set1,v<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> max_dist2 <font color='#5555FF'>=</font> <font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set2,v<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>which<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>set1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> max_dist1 <font color='#5555FF'>&lt;</font> dist_thresh<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> min_dist2 <font color='#5555FF'>&gt;</font> dist_thresh <font face='Lucida Console'>)</font>
                <b>{</b>
                    set1.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>v<font face='Lucida Console'>)</font>;
                    which <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>which;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>set2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> max_dist2 <font color='#5555FF'>&lt;</font> dist_thresh<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> min_dist1 <font color='#5555FF'>&gt;</font> dist_thresh<font face='Lucida Console'>)</font>
                <b>{</b>
                    set2.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>v<font face='Lucida Console'>)</font>;
                    which <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>which;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>set1.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> set1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>set2.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> set2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// make sure we generated the points correctly.
</font>        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>dist_thresh: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> dist_thresh;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>max distance between set1 and set1: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set1,set1<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>max distance between set2 and set2: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set2,set2<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set1,set1<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> dist_thresh<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max_distance_to</font><font face='Lucida Console'>(</font>set2,set2<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> dist_thresh<font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>min distance between set2 and set1: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>min_distance_to</font><font face='Lucida Console'>(</font>set2,set1<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>min_distance_to</font><font face='Lucida Console'>(</font>set2,set1<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> dist_thresh<font face='Lucida Console'>)</font>;

        
        <font color='#009900'>// It is slightly counterintuitive but true that points picked using the above procedure
</font>        <font color='#009900'>// will have elements of their convex hulls that are much closer together than
</font>        <font color='#009900'>// dist_thresh, even though none of the vertices of the hulls are that close
</font>        <font color='#009900'>// together.  This is especially true in high dimensions.  So let's use this to
</font>        <font color='#009900'>// test find_gap_between_convex_hulls().  It should be able to find a pair of
</font>        <font color='#009900'>// points in the convex hulls of our sets that are a lot closer together than
</font>        <font color='#009900'>// dist_thresh.
</font>
        <font color='#009900'>// First we need to convert the vectors to matrices.
</font>        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> A, B;
        A.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>set1[<font color='#979000'>0</font>].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, set1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        B.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>set2[<font color='#979000'>0</font>].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, set2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> A.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>set_colm</font><font face='Lucida Console'>(</font>A,c<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> set1[c];
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> B.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>set_colm</font><font face='Lucida Console'>(</font>B,c<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> set2[c];

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> c1, c2;
        <font color='#BB00BB'>find_gap_between_convex_hulls</font><font face='Lucida Console'>(</font>A, B, c1, c2, <font color='#979000'>0.0001</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// make sure c1 and c2 are convex combinations.
</font>        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>c1<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>c2<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>c1<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>c2<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// now test that the points found are close together.
</font>        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>dist: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>A<font color='#5555FF'>*</font>c1 <font color='#5555FF'>-</font> B<font color='#5555FF'>*</font>c2<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>A<font color='#5555FF'>*</font>c1 <font color='#5555FF'>-</font> B<font color='#5555FF'>*</font>c2<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>4</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_solve_qp_box_constrained_blockdiag'></a>test_solve_qp_box_constrained_blockdiag</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        dlib::rand rnd;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> iter <font color='#5555FF'>=</font> <font color='#979000'>0</font>; iter <font color='#5555FF'>&lt;</font> <font color='#979000'>50</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>iter<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> Q1, Q2;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> b1, b2;

            Q1 <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>4</font>,rnd<font face='Lucida Console'>)</font>; Q1 <font color='#5555FF'>=</font> Q1<font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>Q1<font face='Lucida Console'>)</font>;
            Q2 <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>4</font>,rnd<font face='Lucida Console'>)</font>; Q2 <font color='#5555FF'>=</font> Q2<font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>Q2<font face='Lucida Console'>)</font>;
            b1 <font color='#5555FF'>=</font> <font color='#BB00BB'>gaussian_randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font>, iter<font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            b2 <font color='#5555FF'>=</font> <font color='#BB00BB'>gaussian_randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font>, iter<font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            std::map<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>&gt;</font>, matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> offdiag;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                offdiag[<font color='#BB00BB'>make_unordered_pair</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font>,rnd<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                offdiag[<font color='#BB00BB'>make_unordered_pair</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font>,rnd<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                offdiag[<font color='#BB00BB'>make_unordered_pair</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font>,rnd<font face='Lucida Console'>)</font>;

            std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> Q_blocks <font color='#5555FF'>=</font> <b>{</b>Q1, Q2<b>}</b>;
            std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> bs <font color='#5555FF'>=</font> <b>{</b>b1, b2<b>}</b>;


            <font color='#009900'>// make the single big Q and b
</font>            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> Q <font color='#5555FF'>=</font> <font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font><font color='#BB00BB'>join_rows</font><font face='Lucida Console'>(</font>Q1, <font color='#BB00BB'>zeros_matrix</font><font face='Lucida Console'>(</font>Q1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
                <font color='#BB00BB'>join_rows</font><font face='Lucida Console'>(</font><font color='#BB00BB'>zeros_matrix</font><font face='Lucida Console'>(</font>Q2<font face='Lucida Console'>)</font>,Q2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> b <font color='#5555FF'>=</font> <font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>b1,b2<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> p : offdiag<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> p.first.first;
                <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> p.first.second;
                <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>Q, <font color='#979000'>4</font><font color='#5555FF'>*</font>r,<font color='#979000'>4</font><font color='#5555FF'>*</font>c, <font color='#979000'>4</font>,<font color='#979000'>4</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>diagm</font><font face='Lucida Console'>(</font>p.second<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>c <font color='#5555FF'>!</font><font color='#5555FF'>=</font> r<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>Q, <font color='#979000'>4</font><font color='#5555FF'>*</font>c,<font color='#979000'>4</font><font color='#5555FF'>*</font>r, <font color='#979000'>4</font>,<font color='#979000'>4</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>diagm</font><font face='Lucida Console'>(</font>p.second<font face='Lucida Console'>)</font>;
            <b>}</b>


            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> alpha <font color='#5555FF'>=</font> <font color='#BB00BB'>zeros_matrix</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> lower <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> upper <font color='#5555FF'>=</font> <font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>auto</font> iters <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained</font><font face='Lucida Console'>(</font>Q, b, alpha, lower, upper, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>10000</font><font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO;

            std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alphas</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            alphas[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> zeros_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>; alphas[<font color='#979000'>1</font>] <font color='#5555FF'>=</font> zeros_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>4</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            lower <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
            upper <font color='#5555FF'>=</font> <font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
            std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> lowers <font color='#5555FF'>=</font> <b>{</b>lower,lower<b>}</b>, uppers <font color='#5555FF'>=</font> <b>{</b>upper, upper<b>}</b>;
            <font color='#0000FF'>auto</font> iters2 <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained_blockdiag</font><font face='Lucida Console'>(</font>Q_blocks, bs, offdiag, alphas, lowers, uppers, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>10000</font><font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters2: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters2;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>obj1: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>Q<font color='#5555FF'>*</font>alpha <font color='#5555FF'>+</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>alpha;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>obj2: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>Q<font color='#5555FF'>*</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>obj1-obj2: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font><font face='Lucida Console'>(</font><font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>Q<font color='#5555FF'>*</font>alpha <font color='#5555FF'>+</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>alpha<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>Q<font color='#5555FF'>*</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>],alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha <font color='#5555FF'>-</font> <font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>], alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>6</font>, <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>alpha <font color='#5555FF'>-</font> <font color='#BB00BB'>join_cols</font><font face='Lucida Console'>(</font>alphas[<font color='#979000'>0</font>], alphas[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>iters <font color='#5555FF'>=</font><font color='#5555FF'>=</font> iters2<font face='Lucida Console'>)</font>;

        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_solve_qp_box_constrained'></a>test_solve_qp_box_constrained</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>test_solve_qp_box_constrained()</font>";
        <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        dlib::rand rnd;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> m <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>6</font>,<font color='#979000'>6</font>,rnd<font face='Lucida Console'>)</font>;
        m <font color='#5555FF'>=</font> m<font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> b <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font><font color='#979000'>6</font>,<font color='#979000'>1</font>,rnd<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>0.5</font>;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> lower, upper, solution;
        lower <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>6</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>1e100</font>;
        upper <font color='#5555FF'>=</font> ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>6</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>1e100</font>;

        solution <font color='#5555FF'>=</font> <font color='#BB00BB'>zeros_matrix</font><font face='Lucida Console'>(</font>lower<font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> iters <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained</font><font face='Lucida Console'>(</font>m,b,solution, lower, upper<font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters;

        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> true_solution <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#BB00BB'>pinv</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>b;
        <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>solution <font color='#5555FF'>-</font> true_solution<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>6</font>, <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>solution <font color='#5555FF'>-</font> true_solution<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        iters <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained</font><font face='Lucida Console'>(</font>m,b,solution, lower, upper, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>14</font><font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters;

        <font color='#009900'>/*
        const double obj1 = 0.5*trans(solution)*m*solution + trans(solution)*b;
        const double obj2 = 0.5*trans(true_solution)*m*true_solution + trans(true_solution)*b;
        cout &lt;&lt; "iters:" &lt;&lt; iters &lt;&lt; endl;
        cout &lt;&lt; "obj1: "&lt;&lt; obj1 &lt;&lt; endl;
        cout &lt;&lt; "obj2: "&lt;&lt; obj2 &lt;&lt; endl;
        cout &lt;&lt; "obj1-obj2: "&lt;&lt; obj1-obj2 &lt;&lt; endl;
        */</font>

        <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>solution <font color='#5555FF'>-</font> true_solution<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>10</font>, <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>solution <font color='#5555FF'>-</font> true_solution<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='test_solve_qp_box_constrained_blockdiag_compact'></a>test_solve_qp_box_constrained_blockdiag_compact</b><font face='Lucida Console'>(</font>dlib::rand<font color='#5555FF'>&amp;</font> rnd, <font color='#0000FF'><u>double</u></font> percent_off_diag_present<font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>test_solve_qp_box_constrained_blockdiag_compact(), percent_off_diag_present==</font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> percent_off_diag_present;

        std::map<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>&gt;</font>, matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> offdiag;
        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> Q_blocks;
        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> bs;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> num_blocks <font color='#5555FF'>=</font> <font color='#979000'>20</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dims <font color='#5555FF'>=</font> <font color='#979000'>4</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lambda <font color='#5555FF'>=</font> <font color='#979000'>10</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_blocks; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> Q1;
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> b1;
            Q1 <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font>dims,dims,rnd<font face='Lucida Console'>)</font>; Q1 <font color='#5555FF'>=</font> Q1<font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>Q1<font face='Lucida Console'>)</font>;
            b1 <font color='#5555FF'>=</font> <font color='#BB00BB'>gaussian_randm</font><font face='Lucida Console'>(</font>dims,<font color='#979000'>1</font>, i<font face='Lucida Console'>)</font>;

            Q_blocks.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>Q1<font face='Lucida Console'>)</font>;
            bs.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>b1<font face='Lucida Console'>)</font>;

            <font color='#009900'>// test with some graph regularization terms
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> num_blocks; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rnd.<font color='#BB00BB'>get_random_double</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> percent_off_diag_present<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i<font color='#5555FF'>=</font><font color='#5555FF'>=</font>j<font face='Lucida Console'>)</font>
                        offdiag[<font color='#BB00BB'>make_unordered_pair</font><font face='Lucida Console'>(</font>i,j<font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>num_blocks<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>lambda<font color='#5555FF'>*</font>rnd.<font color='#BB00BB'>get_random_double</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>dims,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font>
                        offdiag[<font color='#BB00BB'>make_unordered_pair</font><font face='Lucida Console'>(</font>i,j<font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>lambda<font color='#5555FF'>*</font>rnd.<font color='#BB00BB'>get_random_double</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>dims,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// build out the dense version of the QP so we can test it against the dense solver.
</font>        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>Q</font><font face='Lucida Console'>(</font>num_blocks<font color='#5555FF'>*</font>dims, num_blocks<font color='#5555FF'>*</font>dims<font face='Lucida Console'>)</font>; 
        Q <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font>num_blocks<font color='#5555FF'>*</font>dims<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_blocks; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>Q,i<font color='#5555FF'>*</font>dims,i<font color='#5555FF'>*</font>dims,dims,dims<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> Q_blocks[i];
            <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>b,i<font color='#5555FF'>*</font>dims,<font color='#979000'>0</font>,dims,<font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> bs[i];
        <b>}</b>
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> p : offdiag<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> p.first.first;
            <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> p.first.second;
            <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>Q, dims<font color='#5555FF'>*</font>r,dims<font color='#5555FF'>*</font>c, dims,dims<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>diagm</font><font face='Lucida Console'>(</font>p.second<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>c <font color='#5555FF'>!</font><font color='#5555FF'>=</font> r<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>Q, dims<font color='#5555FF'>*</font>c,dims<font color='#5555FF'>*</font>r, dims,dims<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>diagm</font><font face='Lucida Console'>(</font>p.second<font face='Lucida Console'>)</font>;
        <b>}</b>



        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> alpha <font color='#5555FF'>=</font> zeros_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>dims<font color='#5555FF'>*</font>num_blocks,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> lower <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>10000</font><font color='#5555FF'>*</font>ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>dims<font color='#5555FF'>*</font>num_blocks,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> upper <font color='#5555FF'>=</font> <font color='#979000'>10000</font><font color='#5555FF'>*</font>ones_matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>dims<font color='#5555FF'>*</font>num_blocks,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>auto</font> iters <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained</font><font face='Lucida Console'>(</font>Q, b, alpha, lower, upper, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>20000</font><font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters;


        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> init_alpha <font color='#5555FF'>=</font> <font color='#BB00BB'>zeros_matrix</font><font face='Lucida Console'>(</font>bs[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
        lower <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>bs[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
        upper <font color='#5555FF'>=</font> <font color='#979000'>10000</font><font color='#5555FF'>*</font><font color='#BB00BB'>ones_matrix</font><font face='Lucida Console'>(</font>bs[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;

        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>alphas</font><font face='Lucida Console'>(</font>num_blocks, init_alpha<font face='Lucida Console'>)</font>;
        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>lowers</font><font face='Lucida Console'>(</font>num_blocks, lower<font face='Lucida Console'>)</font>;
        std::vector<font color='#5555FF'>&lt;</font>matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>uppers</font><font face='Lucida Console'>(</font>num_blocks, upper<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>auto</font> iters2 <font color='#5555FF'>=</font> <font color='#BB00BB'>solve_qp_box_constrained_blockdiag</font><font face='Lucida Console'>(</font>Q_blocks, bs, offdiag, alphas, lowers, uppers, <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>9</font>, <font color='#979000'>20000</font><font face='Lucida Console'>)</font>;
        dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>iters2: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> iters2;


        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> refalpha <font color='#5555FF'>=</font> <font color='#BB00BB'>reshape</font><font face='Lucida Console'>(</font>alpha, num_blocks, dims<font face='Lucida Console'>)</font>;

        <font color='#009900'>// now make sure the two solvers agree on the outputs.
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> num_blocks; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> dims; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>refalpha</font><font face='Lucida Console'>(</font>r,c<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> alphas[r]<font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>6</font>, std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>refalpha</font><font face='Lucida Console'>(</font>r,c<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> alphas[r]<font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='opt_qp_solver_tester'></a>opt_qp_solver_tester</b> : <font color='#0000FF'>public</font> tester
    <b>{</b>
        <font color='#009900'>/*
            The idea here is just to solve the same problem with two different
            methods and check that they basically agree.  The SMO solver should be
            very accurate but for this problem the BFGS solver is relatively
            inaccurate.  So this test is really just a sanity check on the SMO
            solver.
        */</font>
    <font color='#0000FF'>public</font>:
        <b><a name='opt_qp_solver_tester'></a>opt_qp_solver_tester</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> :
            tester <font face='Lucida Console'>(</font>"<font color='#CC0000'>test_opt_qp_solver</font>",
                    "<font color='#CC0000'>Runs tests on the solve_qp_using_smo component.</font>"<font face='Lucida Console'>)</font>
        <b>{</b>
            thetime <font color='#5555FF'>=</font> <font color='#BB00BB'>time</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        time_t thetime;
        dlib::rand rnd;

        <font color='#0000FF'><u>void</u></font> <b><a name='perform_test'></a>perform_test</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>test_solve_qp_box_constrained</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp4_using_smo</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#5555FF'>+</font><font color='#5555FF'>+</font>thetime;
            <font color='#009900'>//dlog &lt;&lt; LINFO &lt;&lt; "time seed: " &lt;&lt; thetime;
</font>            <font color='#009900'>//rnd.set_seed(cast_to_string(thetime));
</font>
            running_stats<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> rs;

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font color='#979000'>40</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> dims <font color='#5555FF'>=</font> <font color='#979000'>1</font>; dims <font color='#5555FF'>&lt;</font> <font color='#979000'>6</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>dims<font face='Lucida Console'>)</font>
                <b>{</b>
                    rs.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font><font color='#BB00BB'>do_the_test</font><font face='Lucida Console'>(</font>dims, <font color='#979000'>1.0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font color='#979000'>40</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> dims <font color='#5555FF'>=</font> <font color='#979000'>1</font>; dims <font color='#5555FF'>&lt;</font> <font color='#979000'>6</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>dims<font face='Lucida Console'>)</font>
                <b>{</b>
                    rs.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font><font color='#BB00BB'>do_the_test</font><font face='Lucida Console'>(</font>dims, <font color='#979000'>5.0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>disagreement mean: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> rs.<font color='#BB00BB'>mean</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>disagreement stddev: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> rs.<font color='#BB00BB'>stddev</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font>rs.<font color='#BB00BB'>mean</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>0.001</font>, rs.<font color='#BB00BB'>mean</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font>rs.<font color='#BB00BB'>stddev</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>0.001</font>, rs.<font color='#BB00BB'>stddev</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


            <font color='#BB00BB'>test_find_gap_between_convex_hulls</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// try a range of off diagonal sparseness.  We do this to make sure we exercise both
</font>            <font color='#009900'>// the compact and sparse code paths within the solver.
</font>            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>0.001</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>0.01</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>0.04</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>0.10</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>0.50</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>test_solve_qp_box_constrained_blockdiag_compact</font><font face='Lucida Console'>(</font>rnd, <font color='#979000'>1.00</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>double</u></font> <b><a name='do_the_test'></a>do_the_test</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dims,
            <font color='#0000FF'><u>double</u></font> C
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>dims: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> dims;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing with C == </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> C;
            test_smo test;

            test.Q <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font>dims, dims, rnd<font face='Lucida Console'>)</font>;
            test.Q <font color='#5555FF'>=</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>test.Q<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>test.Q;
            test.b <font color='#5555FF'>=</font> <font color='#BB00BB'>randm</font><font face='Lucida Console'>(</font>dims,<font color='#979000'>1</font>, rnd<font face='Lucida Console'>)</font>;
            test.C <font color='#5555FF'>=</font> C;

            test_smo_derivative der;
            der.Q <font color='#5555FF'>=</font> test.Q;
            der.b <font color='#5555FF'>=</font> test.b;
            der.C <font color='#5555FF'>=</font> test.C;


            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>x</font><font face='Lucida Console'>(</font>dims<font face='Lucida Console'>)</font>, <font color='#BB00BB'>alpha</font><font face='Lucida Console'>(</font>dims<font face='Lucida Console'>)</font>;


            test.penalty <font color='#5555FF'>=</font> <font color='#979000'>20000</font>;
            der.penalty <font color='#5555FF'>=</font> test.penalty;

            alpha <font color='#5555FF'>=</font> C<font color='#5555FF'>/</font>alpha.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            x <font color='#5555FF'>=</font> alpha;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_iter <font color='#5555FF'>=</font> <font color='#979000'>400000</font>;
            <font color='#BB00BB'>solve_qp_using_smo</font><font face='Lucida Console'>(</font>test.Q, test.b, alpha, <font color='#979000'>0.00000001</font>, max_iter<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> C<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>13</font>, <font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> C<font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LTRACE <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>alpha: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> alpha;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>SMO: true objective: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>test.Q<font color='#5555FF'>*</font>alpha <font color='#5555FF'>-</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>test.b;


            <font color='#0000FF'><u>double</u></font> obj <font color='#5555FF'>=</font> <font color='#BB00BB'>find_min</font><font face='Lucida Console'>(</font><font color='#BB00BB'>bfgs_search_strategy</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                  <font color='#BB00BB'>objective_delta_stop_strategy</font><font face='Lucida Console'>(</font><font color='#979000'>1e</font><font color='#5555FF'>-</font><font color='#979000'>13</font>, <font color='#979000'>5000</font><font face='Lucida Console'>)</font>,
                                  test,
                                  der,
                                  x,
                                  <font color='#5555FF'>-</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>;


            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>BFGS: objective: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> obj;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>BFGS: true objective: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#979000'>0.5</font><font color='#5555FF'>*</font><font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>test.Q<font color='#5555FF'>*</font>x <font color='#5555FF'>-</font> <font color='#BB00BB'>trans</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>test.b;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>sum(x): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> x;

            <font color='#0000FF'><u>double</u></font> disagreement <font color='#5555FF'>=</font> <font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>-</font>alpha<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>Disagreement: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> disagreement;
            <font color='#0000FF'>return</font> disagreement;
        <b>}</b>
    <b>}</b> a;

<b>}</b>




</pre></body></html>